package com.yanqu.road.server.cmd.vehicle;

import com.yanqu.road.entity.player.UserVehicle;
import com.yanqu.road.entity.player.UserVehicleOtherSkill;
import com.yanqu.road.pb.vehicle.VehicleProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.vehicle.VehicleModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_VEHICLE_SKILL_UPGRADE, desc = "坐骑技能升级")
public class VehicleSkillUpgradeCmd extends AbstractCommand {

	private String vehicleUid;

	private int skillId;

	private int type;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		VehicleProto.VehicleOtherSkillUpgradeReqMsg reqMsg = VehicleProto.VehicleOtherSkillUpgradeReqMsg.parseFrom(packet.getBytes());
		vehicleUid = reqMsg.getVehicleUid();
		skillId = reqMsg.getSkillId();
		type = reqMsg.getType();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = player.getModule(VehicleModule.class).skillUpgrade(vehicleUid, skillId, type);
	}

	@Override
	public void sendData(GamePlayer player) {
		VehicleProto.VehicleOtherSkillUpgradeRespMsg.Builder respMsg = VehicleProto.VehicleOtherSkillUpgradeRespMsg.newBuilder();
		respMsg.setRet(ret);
		if(0 == ret){
			respMsg.setVehicleUid(vehicleUid);
			respMsg.setSkillId(skillId);
			respMsg.setType(type);
			UserVehicle userVehicle = player.getModule(VehicleModule.class).getUserVehicle(vehicleUid);
			UserVehicleOtherSkill skill = userVehicle.getVehicleOtherSkill(type, skillId);
			respMsg.setSkillLv(skill.getSkillLv());
		}
		player.sendPacket(Protocol.U_VEHICLE_SKILL_UPGRADE, respMsg);
	}

}
